package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.VenueDrawingCategoryAuditDTO;
import com.eastfair.venueservice.dto.VenueDrawingCategoryAuditPageQuery;
import com.eastfair.venueservice.dto.VenueDrawingCategoryAuditSaveDTO;
import com.eastfair.venueservice.dto.VenueDrawingCategoryAuditUpdateDTO;
import com.eastfair.venueservice.entity.VenueDrawingCategoryAudit;
import com.eastfair.venueservice.service.VenueDrawingCategoryAuditService;
import com.eastfair.venueservice.vo.VenueDrawingCategoryAuditVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 一键报馆图纸分类审核记录
 * </p>
 *
 * @author dq
 * @date 2022-10-31
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/venueDrawingCategoryAudit")
@Api(value = "VenueDrawingCategoryAudit", tags = "一键报馆图纸分类审核记录")
@PreAuth(replace = "venueservice:venueDrawingCategoryAudit:")
public class VenueDrawingCategoryAuditController extends SuperController<VenueDrawingCategoryAuditService, Long, VenueDrawingCategoryAudit, VenueDrawingCategoryAuditPageQuery, VenueDrawingCategoryAuditSaveDTO, VenueDrawingCategoryAuditUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private VenueDrawingCategoryAuditService venueDrawingCategoryAuditService;

    @Override
    public void handlerResult(IPage<VenueDrawingCategoryAudit> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<VenueDrawingCategoryAudit> venueDrawingCategoryAuditList = list
                .stream()
                .map((map) -> VenueDrawingCategoryAudit.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(venueDrawingCategoryAuditList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<VenueDrawingCategoryAuditPageQuery> params) {
        VenueDrawingCategoryAuditPageQuery pageQuery = params.getModel();
    }

    /**
     * 查询一键报馆图纸分类列表VO.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("查询一键报馆图纸分类列表VO")
    @PostMapping("/query/venueDrawingCategoryAudit")
    public R<Page<VenueDrawingCategoryAuditVO>> queryVenueDrawingCategoryAudit(@RequestBody PageParams<VenueDrawingCategoryAuditDTO> pageParams) {
        log.info("queryVenueDrawingCategoryAudit - 查询一键报馆图纸分类列表VO, pageParams={}", pageParams);
        Page<VenueDrawingCategoryAuditVO> page = venueDrawingCategoryAuditService.listVenueDrawingCategoryAuditVO(pageParams);
        return R.successDef(page);
    }

    /**
     * id查询报馆图纸审核记录VO.
     *
     * @param id the id
     * @return the by id
     */
    @ApiOperation("id查询报馆图纸审核记录VO")
    @PostMapping("/get/{id}")
    public R<VenueDrawingCategoryAuditVO> getById(@PathVariable("id") Long id) {
        log.info("getById - id查询报馆图纸审核记录VO, id={}", id);
        VenueDrawingCategoryAuditVO venueDrawingCategoryAuditVO = venueDrawingCategoryAuditService.getVOById(id);
        return R.successDef(venueDrawingCategoryAuditVO);
    }

    /**
     * 提交报馆图纸审核记录.
     *
     * @param param the param
     * @return the r
     */
    @ApiOperation("提交报馆图纸审核记录")
    @PostMapping("/submit")
    public R<Boolean> submit(@RequestBody VenueDrawingCategoryAuditDTO param) {
        log.info("submit - 提交报馆图纸审核记录, param={}", param);
        try {
            return R.successDef(venueDrawingCategoryAuditService.submitVenueDrawingCategoryAudit(param));
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 批量审核图纸.
     *
     * @param list the list
     * @return the r
     */
    @ApiOperation("批量审核图纸")
    @SysLog("审核图纸")
    @PostMapping("/audit")
    public R<Boolean> auditVenueDrawingCategory(@RequestBody List<VenueDrawingCategoryAuditDTO> list) {
        log.info("auditVenueDrawingCategory - 批量审核图纸, list={}", list);
        return R.successDef(venueDrawingCategoryAuditService.auditBatchVenueDrawing(list));
    }
}
